package com.xiaoyu.lanling.feature.moment.model.notice

import `in`.srain.cube.request.JsonData
import `in`.srain.cube.views.list.ListItemTypedBase
import com.xiaoyu.base.model.User
import com.xiaoyu.base.utils.extensions.dp
import com.xiaoyu.lanling.feature.moment.model.Feed
import com.xiaoyu.lanling.feature.user.model.UserExtra
import com.xiaoyu.lanling.media.image.ImageLoadParam
import com.xiaoyu.lanling.media.image.UserImageLoadParam

class LikeNoticeItem(jsonData: JsonData) : ListItemTypedBase {
    companion object {
        const val TYPE_IMAGE = 0
        const val TYPE_TEXT = 1
    }

    val user = User.fromJson(jsonData.optJson("user"))
    val feed = Feed.fromJson(jsonData.optJson("feed"))
    val verified = jsonData.optJson("user").optString("verify") == UserExtra.VerifyStatus.SUCCESS
    val updateTimeDesc = jsonData.optJson("likeInfo").optString("updateTimeDesc")
    val avatarLoadParam = UserImageLoadParam.newBuilder().setUserAndDP(user, 40).build()
    val feedImageLoadParam =
            ImageLoadParam.newBuilder().setEnableEmptyUrl(true).setUrl(feed.images.firstOrNull()?.imageUrl
                    ?: "").setSize(68).setCornersRadius(4.dp).build()
    val isRead = jsonData.optBoolean("isRead", true)

    override fun getViewType(): Int {
        return if (feed.images.isNotEmpty()) TYPE_IMAGE else TYPE_TEXT
    }
}